package com.lisheny.extendcode.base;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;

import com.lisheny.extendcode.listener.LifeCycleListener;
import com.lisheny.extendcode.utils.ActivityStackManager;
import com.trello.rxlifecycle2.components.RxActivity;

import butterknife.Unbinder;

/**
 * Created by Administrator on 2017/10/27.
 */

public class BaseActivity extends RxActivity{
    protected Context mContext;
    protected Unbinder unbinder;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (mListener != null) {
            mListener.onCreate(savedInstanceState);
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        if (mListener != null) {
            mListener.onStart();
        }
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        if (mListener != null) {
            mListener.onRestart();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (mListener != null) {
            mListener.onResume();
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (mListener != null) {
            mListener.onPause();
        }
    }

    @Override
    protected void onStop() {
        super.onStop();
        if (mListener != null) {
            mListener.onStop();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mListener != null) {
            mListener.onDestroy();
        }

        ActivityStackManager.getManager().remove(this);
    }

    /**
     * 回调函数
     */
    public LifeCycleListener mListener;

    public void setOnLifeCycleListener(LifeCycleListener listener) {
        mListener = listener;
    }
}
